<?php
$title = "主页更改";
include 'version.php';
include 'upzip.php';
   
                        function downFile($url,$path){
                       $arr=parse_url($url);
                       $fileName=basename($arr['path']);
                        $file=file_get_contents($url);
                       file_put_contents($path.$fileName,$file);
                       return $fileName;
                          }
                        if(isset($_POST["act"])){
                     include 'checklogin.php';
                            $act=daddslashes($_POST["act"]);
                     $check=json_decode(file_get_contents(base64_decode("aHR0cHM6Ly93d3cuOWd5dW4uY24vQ2hlY2svdXBkYXRlLnBocA==")."?url={$_SERVER['HTTP_HOST']}&token={$con['token']}&type=pzp&version=".$version));
                            if($act=='up'){
                                  if($version<$check->version){
                                      $sql=$check->upsql;
                                      $zip=$check->upzip;
                                      $readsql=file_get_contents($sql);
                                      $upsql=explode(";",$readsql);
                                      foreach ($upsql as $key=>$value){
                                          @$pdo->exec($value);
                                      }
                                      $fileName=downFile($zip,"../");
                                      $actzip=unZip('../'.$fileName,'../');
                                      $state=1;
                                  }else{
                                      $state=0;
                                  }
                                  exit(json_encode(["state"=>$state]));
                            }
                        }else{
                            include 'header.php';
                                             $check=json_decode(file_get_contents(base64_decode("aHR0cHM6Ly93d3cuOWd5dW4uY24vQ2hlY2svdXBkYXRlLnBocA==")."?url={$_SERVER['HTTP_HOST']}&token={$con['token']}&type=pzp&version=".$version));
                    $code=$check->state;
                    if(!isset($code)){
                    $msg="效验失败了，请联系客服QQ80808202了解情况";
                   }else{
                   if ($code<>1) {
                    $msg='你的程序未通过授权，请前往云风轻授权中心<a href="https://www.9gyun.cn">www.9gyun.cn</a>购买授权';
                    }else{
                        if($version>=$check->version){
                            $msg='        <div class="col-lg-12">
                <div class="card alert border p-0 mb-0">
                    <div class="card-header bg-soft-success">
                        <div class="d-flex">
                            <div class="flex-grow-1">
                                <h5 class="font-size-16 text-success my-1">已经是最新版本</h5>
                            </div>
                        </div>
                    </div>
                    <div class="card-body">
                        <div class="text-center">
                            <div class="mb-4"><i class="mdi mdi-checkbox-marked-circle-outline display-4 text-success"></i></div>
                            <h4 class="alert-heading font-18">已经是最新版本!</h4>
                            <p class="mb-0">当前版本：V'.$version.'</p>
                        </div>
                    </div>
                </div>
            </div>';
                        }
                        if($version<$check->version){
                            $msg='           <div class="col-lg-12">
                <div class="card alert border mt-4 mt-lg-0 p-0 mb-0">
                    <div class="card-header bg-soft-info">
                        <div class="d-flex">
                            <div class="flex-grow-1">
                                <h5 class="font-size-16 text-info my-1">检测到有最新版本</h5>
                            </div>
                        </div>
                    </div>
                    <div class="card-body">
                        <div class="text-center">
                            <div class="mb-4"><i class="mdi mdi-cloud-circle display-4 text-info"></i></div>
                            <h4 class="alert-heading font-18">检测到最新版本V'.$check->version.'</h4>
                             <p style="color:red;" class="mb-0">目前版本: V'.$version.'</p>
                            <p class="mb-0"><button onclick="return update();" type="button" class="btn btn-success btn-rounded waves-effect waves-light">开始更新</button></p>
                        </div>
                    </div>
                </div>
            </div>';
                            //执行数据库语句
                            //下载更新包并解压
                        }
                        
                       }
                        }
                        }
?>
<link href="../assets/js/materialdesignicons.min.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="../assets/css/webuploader.css">
<link href="../assets/css/sweetalert2.min.css" rel="stylesheet" type="text/css">
<!--页面主要内容-->
<div class="main-content">
    <div class="page-content">
        <div class="container-fluid">
            <!-- start page title -->
            <div class="row">
                <div class="col-xl-4 offset-xl-4">
                 <div class="card">
    <div class="card-body">
        <h4 class="card-title">检查更新</h4>
        <p class="card-title-desc"></p>
        <div class="row">
            <?php echo $msg; ?>
        
        </div><!-- end row -->
    </div>
</div>
                </div><!-- end col -->
            </div><!-- end row -->
        </div><!-- container-fluid -->
    </div><!-- End Page-content -->
    <footer class="footer">
        <div class="container-fluid">
            <div class="row">
                <div class="col-sm-6">
                    <script>
                        document.write(new Date().getFullYear())
                    </script>(c) Cloud.
                </div>
                <div class="col-sm-6">
                    <div class="text-sm-end d-none d-sm-block">Crafted with <i class="mdi mdi-heart text-danger"></i>By <a href="https://www.9gyun.cn">云风轻产品授权中心</a></div>
                </div>
            </div>
        </div>
    </footer>
</div><!-- end main content-->
<!--End 页面主要内容-->
<?php include("footer.php"); ?>
<script src="../assets/js/sweetalert2.min.js"></script>
<script>
function update(){
       $.ajax({
            type: "POST",
            url: "update.php",
            data: {
                act:'up',
            },
            dataType: "json",
            success: function(data) {
                if (data.state == 1) {
                    Swal.fire("更新成功!", "恭喜你，更新成功了!", "success");
                    setTimeout(function() {
                        window.location = './update.php';
                    }, 1000);
                }else{
                    Swal.fire("更新失败!", "可能已经是最新版本!", "error");
                }

            },
            error: function(data) {
            Swal.fire("更新失败!", "无文件更新权限，请检查!", "error");
            }
        });
}
</script>
</body>

</html>